/*
* Copyright (C) 2008-2009 J-P Nurmi jpnurmi@gmail.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
* License for more details.
*
* $Id: ircsession.h 581 2009-05-19 16:40:38Z jpnurmi $
*/

#ifndef IRC_SESSION_H
#define IRC_SESSION_H

#include <ircglobal.h>
#include <QObject>

QT_FORWARD_DECLARE_CLASS(QAbstractSocket)

namespace Irc
{
    class Buffer;
    class ServerBuffer;
    class ChannelBuffer;
    class SessionPrivate;

    class IRC_EXPORT Session : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QByteArray encoding READ encoding WRITE setEncoding)

    public:
        Session(QObject* parent = 0);
        ~Session();

        QByteArray encoding() const;
        void setEncoding(const QByteArray& encoding);

        ServerBuffer* connectToServer(const QString& host, quint16 port = 6667);
        ChannelBuffer* joinChannel(const QByteArray& channel, const QByteArray& key = QByteArray());
        Buffer* openQuery(const QByteArray& user);

        Buffer* buffer(const QByteArray& name = QByteArray()) const;

        QAbstractSocket* socket() const;
        void setSocket(QAbstractSocket* socket);

    Q_SIGNALS:
        void bufferAvailable(Buffer* buffer);

        /*
        bool cmdJoin(const QString& channel, const QString& key = QString());
        bool cmdQuit(const QString& reason = QString());
        bool cmdNames(const QString& channel);
        bool cmdList(const QString& channel = QString());
        bool cmdWhois(const QString& nick);
        bool cmdWhowas(const QString& nick);
        */

        /*
    Q_SIGNALS:
        void msgQuit(const QString& origin, const QString& message);
        void msgNickChanged(const QString& origin, const QString& nick);
        void msgInvited(const QString& origin, const QString& receiver, const QString& channel);
        void msgUnknownMessageReceived(const QString& origin, const QStringList& params);
        */

    private:
        SessionPrivate* const d_ptr;
        Q_DECLARE_PRIVATE(Session)
        Q_DISABLE_COPY(Session)
        
        Q_PRIVATE_SLOT(d_func(), void _q_connected())
        Q_PRIVATE_SLOT(d_func(), void _q_disconnected())
        Q_PRIVATE_SLOT(d_func(), void _q_error())
        Q_PRIVATE_SLOT(d_func(), void _q_state())
        Q_PRIVATE_SLOT(d_func(), void _q_readData())
    };
}

#endif // IRC_SESSION_H
